;
$(function () {

    var ad = appData();
    var tmpObj = {};

    showMenu();

    $(".other-click").click(function () {
        $(".other-lists").slideToggle();
    })

    function showMenu() {
        // ad.sel("INDEX_MENU", {id:"auth"}, function (data) {
        ad.selectMenu("INDEX_MENU", {}, function (data) {
            $.tmpl(tmpObj.menu, data).appendTo("#sys-menu ul");
            $("#sys-menu a").on("click", function () {
                var $this = $(this),
                    url = $this.attr("data-url");

                sessionStorage.appUrl = url;
                $('#sys-main').empty().load(url + ".html");
            })
        });

        ad.selectMenu("ALL_SYSTEM_LINK", {}, function (data) {
            $.tmpl(tmpObj.a, data).appendTo("ul.other-lists");
            $("ul.other-lists").on("click", "li", function () {
                window.location.href = $(this).attr("data-url");
            })
        });

        ad.selectList("D_USER", {}, function (data) {
            $("#user").html('<i class="icon-person"></i>' + data);
        })
    }

    if (sessionStorage.appUrl) {
        $('#sys-main').empty().load(sessionStorage.appUrl + ".html");
    } else {
        $('#sys-main').empty().load("views/users/user.html");
    }

    $(".logout-btn").on("click", function () {
        window.location.href = appApi("LOGOUT");
    });

    (function getTemp() {
        tmpObj.menu = "\n<li><a href=\"javascript:void(0);\" data-url=\"{{= url}}\">{{= name}}</a></li>\n";
        tmpObj.a = '<li data-url="{{= systemUrl}}" data-systemid="{{= systemId}}"><a href="javascript:void(0);">{{= systemName}}</a></li>';
    })();

})